package org.dromara.common.core.utils;

import cn.hutool.core.util.RandomUtil;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class RandomUtils {




    public static String generateId() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
        String timePart = LocalDateTime.now().format(formatter);
        int random = RandomUtil.randomInt(10000, 99999);
        return timePart + random; // 变成14位
    }


    public static String generateOrderId() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
        String timePart = LocalDateTime.now().format(formatter);
        int random = RandomUtil.randomInt(10000, 99999);
        return "DD"+timePart + random; // 变成14位
    }


    public static String generateOrderNoId() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
        String timePart = LocalDateTime.now().format(formatter);
        int random = RandomUtil.randomInt(10000, 99999);
        return "WX"+timePart + random; // 变成14位
    }


    public static void main(String[] args) {
        System.out.println(generateId());
    }



    /**
     * 获取一个随机数
     *
     * @param min 最小数(包含在值内)
     * @param max 最大数(不包含在值内)
     * @return
     */
    public static int number(int min, int max) {
        return ThreadLocalRandom.current().nextInt(min, max);
    }

    /**
     * 获取一个随机数
     * 获取的随机数不包含本身
     *
     * @return
     */
    public static int number(int max) {
        Random r = new Random();
        return r.nextInt(max);
    }

}
